<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@include file="../common/header.jsp"%>
<div class="easyui-layout" data-options="fit:true">
    <!-- Begin of toolbar -->
    <div id="wu-toolbar">
        <div class="wu-toolbar-button">
            <%@include file="../common/menus.jsp"%>
        </div>
        <div class="wu-toolbar-search">
            <label>评论内容:</label><input id="search-name" class="wu-text" style="width:100px">
            <a href="#" id="search-btn" class="easyui-linkbutton" iconCls="icon-search">搜索</a>
        </div>
    </div>
    <!-- End of toolbar -->
    <table id="data-datagrid" class="easyui-datagrid" toolbar="#wu-toolbar"></table>
</div>

<%@include file="../common/footer.jsp"%>

<!-- End of easyui-dialog -->
<script type="text/javascript">
	
	
	
	
	/**
	* 删除记录
	*/
	function remove(){
		$.messager.confirm('信息提示','确定要删除该记录？', function(result){
			if(result){
				var item = $('#data-datagrid').datagrid('getSelections');
				if(item == null || item.length == 0){
					$.messager.alert('信息提示','请选择要删除的数据！','info');
					return;
				}
				var ids = '';
				for(var i=0;i<item.length;i++){
					ids += item[i].id + ',';
				}
				$.ajax({
					url:'delete_comment',
					dataType:'json',
					type:'post',
					data:{ids:ids},
					success:function(data){
						$("#data-datagrid").datagrid('clearSelections');
						if(data.type == 'success'){
							$.messager.alert('信息提示','删除成功！','info');
							$('#data-datagrid').datagrid('reload');
						}else{
							$.messager.alert('信息提示',data.msg,'warning');
						}
					}
				});
			}	
		});
	}
	
	
	
	//使field能够点接
	function formatterPoint(value, rec, index){

		var field = this.field;

		var rs = eval("rec['"+field.replace(/\./g,"']['")+"']");  
		 
		var sub_rs = rs.substring(rs.length-4,rs.length)
	
		 
		if(".jpg" == sub_rs  || ".jpeg" == sub_rs || ".png" == sub_rs || ".gif" == sub_rs)
		{
			var img = '<img src="'+rs+'" width="50px" height="50px"/>';
			return img;
		}else{
			
			return rs;
		}
	}
	
	//搜索按钮监听
	$("#search-btn").click(function(){
		
		var option = {content:$("#search-name").val()};
		
		$('#data-datagrid').datagrid('reload',option);
	});
	
	
	function add0(m){return m<10?'0'+m:m }
	function format(shijianchuo){
	//shijianchuo是整数，否则要parseInt转换
		var time = new Date(shijianchuo);
		var y = time.getFullYear();
		var m = time.getMonth()+1;
		var d = time.getDate();
		var h = time.getHours();
		var mm = time.getMinutes();
		var s = time.getSeconds();
		return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
	}
	
	
	/** 
	* 载入数据
	*/
	$('#data-datagrid').datagrid({
		url:'comment',
		rownumbers:true,
		singleSelect:false,
		pageSize:20,           
		pagination:true,
		multiSort:true,
		fitColumns:true,
		idField:'id',
		fit:true,
		columns:[[
			{ field:'chk',checkbox:true},
			{ field:'tea.photo',title:'商品图片',width:60,align:'center',formatter:formatterPoint},
			{ field:'tea.name',title:'商品名称',width:150,align:'center',formatter:formatterPoint},
			{ field:'content',title:'评论内容',width:300,align:'center'},
			{ field:'account.username',title:'评论人',width:100,align:'center',formatter:formatterPoint},
			{ field:'time',title:'评论时间',width:100,align:'center',formatter:function(value,row,index){
				return format(value);
			}}
		]]
	});
</script>